Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to talk to Kafka over TLS rather than plaintext #21

Merged
merged 3 commits into from
Feb 1, 2018

Conversation

aeijdenberg
Copy link
Contributor

(and make this the default unless opt-in to no TLS)

To see an example of this being used, see https://github.com/govau/kafka-boshrelease/tree/moartls (particularly the example operator files that add it to a cf-deployment) - I'm still working out how best to make a PR there.

I'm guessing that in order to accept this PR, you might want to flip the default back to current state (ie plaintext), but I thought I'd start with "secure by default", as that seems to match best the "insecure_skip_ssl_verify" and similar flags used elsewhere.

@CAFxX
Copy link
Contributor

CAFxX commented Dec 16, 2017

@aeijdenberg thanks for the PR! A few early feedbacks:

  • There seem to be no tests that cover TLS... can you add some, e.g. TLS enabled and cert match, TLS enabled and cert mismatch, incoherent options? No need to run all existing tests in all configurations (TLS enabled and disabled) but at least some tests should cover this, since refactorings may lead to security issues.
  • (cosmetic) I would prefer to maintain the Sarama option names, since they map one-to-one. Most of them already do so this would mean mostly just renaming InsecurePlainText to EnableTLS or something like that, and default it to false (as you suggested in the PR description)
  • I'll add other feedback inline

kafka.go Outdated
@@ -27,6 +30,38 @@ func NewKafkaProducer(logger *log.Logger, stats *Stats, config *Config) (NozzleP
// TODO (tcnksm): Enable to configure more properties.
producerConfig := sarama.NewConfig()

if !config.Kafka.InsecurePlainText {
if len(config.Kafka.CACerts) == 0 {
return nil, errors.New("please specify at least one ca_certificate, else set insecure_use_plaintext")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is specifying additional CA certs really required? what if the kafka cert is already signed by a trusted CA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be sensible to use the system trusted roots if no CA certs are specified - I'll update the PR to do so (am on holiday break now, so will be likely be in a few weeks).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to default to system CA pool if no CAs are specified.

kafka.go Outdated
return nil, errors.New("please specify at least one ca_certificate, else set insecure_use_plaintext")
}
if config.Kafka.ClientCert == "" {
return nil, errors.New("please specify client_certificate, else set insecure_use_plaintext")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is mutual TLS required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if strictly required by Kafka or not - but I'm not sure it would be sensible not to. ie the client cert is used to authenticate the client to Kafka - so if not presented I guess at the least the connection is encrypted, but the server would still be wide open. (I may be missing a use-case?)

@aeijdenberg
Copy link
Contributor Author

Apparently x509.SystemCertPool() was added in in Golang 1.7, and I guess the CI is on an older version? Let me know if it's important to support older versions.

@aeijdenberg
Copy link
Contributor Author

Upstream sarama has now merged the PR I sent to add a function needed for testing.

Have rebased on current master with a commit to update the vendored version of sarama, and then squashed the other commits for this change into one, including some basic tests.

Note that I contributed some of those same tests into sarama as well, so I don't know if we should repeat them here or not.

@CAFxX
Copy link
Contributor

CAFxX commented Jan 18, 2018

Apparently x509.SystemCertPool() was added in in Golang 1.7, and I guess the CI is on an older version? Let me know if it's important to support older versions.

@aeijdenberg no, feel free to bump to 1.9.x+tip

@aeijdenberg
Copy link
Contributor Author

@CAFxX - is there anything else that you're waiting for me on?

I think I fixed the last tests (failing on Go 1.6 - by simply excluding Go 1.6 from testing).

@CAFxX CAFxX self-assigned this Jan 31, 2018
@CAFxX
Copy link
Contributor

CAFxX commented Feb 1, 2018

Should be OK to merge, I'm just waiting for internal approval to proceed (sorry!)

@CAFxX CAFxX merged commit d9cf013 into rakutentech:master Feb 1, 2018
@CAFxX
Copy link
Contributor

CAFxX commented Feb 1, 2018

@aeijdenberg merged and closed, thanks!

@aeijdenberg
Copy link
Contributor Author

@CAFxX - you are most welcome! Now I need to go and finish work on the other side - kafka-boshrelease...

@aeijdenberg aeijdenberg deleted the moartls branch February 1, 2018 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants